package com.okcl.common.handler;

import com.okcl.common.exception.BusinessException;
import com.okcl.model.vo.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e) {
        log.error("全局异常捕获 {}", e.getMessage());
        return Result.build(null, 201, "系统异常");
    }

    @ExceptionHandler(BusinessException.class)
    public Result handleBusinessException(BusinessException e) {
        log.error("业务异常捕获 {}", e.getMessage());
        return Result.build(null, e.getCode(), e.getMessage());
    }
}
